using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using SQLDAL;

/// <summary>
/// Summary description for OrderFoodBll
/// </summary>
public class OrderFoodBll
{
	public OrderFoodBll()
	{
		//
		// TODO: Add constructor logic here
        //

    }

    string sp_Date = "sp_OrderingFood_ListAllOrderFoodOfRestaurant_ByDate";
    string sp_Month = "sp_OrderingFood_ListAllOrderFoodOfRestaurant_ByMonth";
    string sp_Year = "sp_OrderingFood_ListAllOrderFoodOfRestaurant_ByYear";

    #region List All Order Food
    public SqlDataReader ListAllOrderFood()
    {
        return (SQLHelper.ExecuteReader(SQLHelper.CONN_STRING,CommandType.StoredProcedure, "sp_OrderingFood_List", null));
    }
    #endregion

    #region List all food older of restaurant by date
    public SqlDataReader ListAllFoodOrderOfRestaurantByDate(OrderFoodInfo orderFoodInfo, RestaurantInfo resInfo)
    {
        SqlParameter[] parms = 
            {
                new SqlParameter("@dateOfOrder",SqlDbType.DateTime),
                new SqlParameter("@resID", SqlDbType.VarChar)
            };
        parms[0].Value = orderFoodInfo.DateOfOrder.Date;
        parms[1].Value = resInfo.ResID;  
        return SQLHelper.ExecuteReader(SQLHelper.CONN_STRING, CommandType.StoredProcedure, sp_Date, parms);
    }
    #endregion

    #region List all food orders of restaurants order by month
    public SqlDataReader ListAllFoodOrderOfRestaurantByMonth(int month, RestaurantInfo resInfo)
    {
        SqlParameter[] parms = 
            {
                new SqlParameter("@month",SqlDbType.Int),
                new SqlParameter("@resID", SqlDbType.VarChar)
            };
        parms[0].Value = month;
        parms[1].Value = resInfo.ResID;                
        
        return SQLHelper.ExecuteReader(SQLHelper.CONN_STRING, CommandType.StoredProcedure, sp_Month, parms);
    }
    #endregion

    #region List all food orders of restaurants order by year

    public SqlDataReader ListAllFoodOrderOfRestaurantByYear(int year, RestaurantInfo resInfo)
    {
        SqlParameter[] parms = 
            {
                new SqlParameter("@year",SqlDbType.Int),
                new SqlParameter("@resID", SqlDbType.VarChar)
            };
        parms[0].Value = year;
        parms[1].Value = resInfo.ResID;  
        return SQLHelper.ExecuteReader(SQLHelper.CONN_STRING, CommandType.StoredProcedure, sp_Year, parms);
    }
    #endregion

    #region Create a order food
    public int CreateOrderFood(OrderFoodInfo orderFoodInfo)
    {
        SqlParameter[] cmdParms =
            {
                new SqlParameter("@orderID", SqlDbType.VarChar, 5),
                new SqlParameter("@customerName", SqlDbType.VarChar, 50),
                new SqlParameter("@deliverName", SqlDbType.VarChar, 50),
                new SqlParameter("@deliverAddress", SqlDbType.VarChar, 50),
                new SqlParameter("@email", SqlDbType.VarChar, 50),
                new SqlParameter("@phone", SqlDbType.VarChar, 12),
                new SqlParameter("@acc_no", SqlDbType.VarChar, 20),
                new SqlParameter("@dateOfOrder", SqlDbType.DateTime,8),
                new SqlParameter("@timeNeedDeliver", SqlDbType.VarChar, 8),
                new SqlParameter("@description", SqlDbType.VarChar, 1000),
                new SqlParameter("@status", SqlDbType.Int,4)
            };
        cmdParms[0].Value = orderFoodInfo.OrderID;
        cmdParms[1].Value = orderFoodInfo.CustomerName;
        cmdParms[2].Value = orderFoodInfo.DeliverName;
        cmdParms[3].Value = orderFoodInfo.DeliverAddress;
        cmdParms[4].Value = orderFoodInfo.Email;
        cmdParms[5].Value = orderFoodInfo.Phone;
        cmdParms[6].Value = orderFoodInfo.AccNo;
        cmdParms[7].Value = orderFoodInfo.DateOfOrder;
        cmdParms[8].Value = orderFoodInfo.TimeNeedDeliver;
        cmdParms[9].Value = orderFoodInfo.Description;
        cmdParms[10].Value = orderFoodInfo.Status;

        int result = SQLHelper.ExecuteNonQuery(SQLHelper.CONN_STRING,
            CommandType.StoredProcedure, "sp_OrderingFood_Create", cmdParms);
        
        return result;
    }

    #endregion

    #region Update a order food
    public int UpdateOrderFood(OrderFoodInfo orderFoodInfo)
    {
        SqlParameter[] cmdParms =
            {
                new SqlParameter("@orderID", SqlDbType.VarChar, 5),
                new SqlParameter("@customerName", SqlDbType.VarChar, 50),
                new SqlParameter("@deliverName", SqlDbType.VarChar, 50),
                new SqlParameter("@deliverAddress", SqlDbType.VarChar, 50),
                new SqlParameter("@email", SqlDbType.VarChar, 50),
                new SqlParameter("@phone", SqlDbType.VarChar, 12),
                new SqlParameter("@acc_no", SqlDbType.VarChar, 20),
                new SqlParameter("@dateOfOrder", SqlDbType.DateTime),
                new SqlParameter("@timeNeedDeliver", SqlDbType.VarChar, 8),
                new SqlParameter("@description", SqlDbType.VarChar, 1000),
                new SqlParameter("@status", SqlDbType.Int)
            };
        cmdParms[0].Value = orderFoodInfo.OrderID;
        cmdParms[1].Value = orderFoodInfo.CustomerName;
        cmdParms[2].Value = orderFoodInfo.DeliverName;
        cmdParms[3].Value = orderFoodInfo.DeliverAddress;
        cmdParms[4].Value = orderFoodInfo.Email;
        cmdParms[5].Value = orderFoodInfo.Phone;
        cmdParms[6].Value = orderFoodInfo.AccNo;
        cmdParms[7].Value = orderFoodInfo.DateOfOrder;
        cmdParms[8].Value = orderFoodInfo.TimeNeedDeliver;
        cmdParms[9].Value = orderFoodInfo.Description;
        cmdParms[10].Value = orderFoodInfo.Status;

        int result = SQLHelper.ExecuteNonQuery(SQLHelper.CONN_STRING,
            CommandType.StoredProcedure, "sp_OrderingFood_Update", cmdParms);

        return result;
    }
    #endregion

    #region Delete a order food
    public int DeleteOrderFood(OrderFoodInfo orderFoodInfo)
    {
        SqlParameter[] cmdParms =
            {
                new SqlParameter("@orderID", SqlDbType.VarChar, 5)
            };
        cmdParms[0].Value = orderFoodInfo.OrderID;

        int result = SQLHelper.ExecuteNonQuery(SQLHelper.CONN_STRING,
            CommandType.StoredProcedure, "sp_OrderingFood_Delete", cmdParms);
        return result;
    }
    #endregion
}
